package kr.hkit.powerjava.chapter22.submit2.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.submit2.vo.Department;

public class DepartmentManagerImpl implements ItemDaoInterface<Department> {
	private ArrayList<Department> arList;

	public DepartmentManagerImpl(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		arList.add(item);
	}

	@Override
	public void delItem(Department item) {
		arList.remove(item);
	}

	@Override
	public void updateItem(Department item) { //수정
		if(searchItem(item)) {
		arList.set(arList.indexOf(item), item);
		}else{
			System.out.println("수정 불가");
		}
	}

	@Override
	public boolean searchItem(Department item) {
		return arList.contains(item); //contains가 참이면 존재한다 
	}

	
	@Override
	public void prnItems() {
		prnHeader();
		for (Department dept : arList) {
			System.out.println(dept);
		}
	}
	
	
	private void prnHeader() {
		 String str = String
			.format("%10s\t%4s\t%3s","학과번호", "학과명", "학과위치(층)");
		 System.out.println(str);
		 System.out.println("--------------------------------------");
	}


	@Override
	public void prnItems(Comparator<Department> comp) { 
		Collections.sort(arList,comp); //collections라는 클래스가 있음 
		prnItems();
		
	}

}
